<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 为数组添加一个共享方法，将数组中的奇数个挑选出来存放到新数组中并返回(数组中的第一个元素、第三个元素、第五个元素......)
        // Array.prototype.selectOdd=function(){
        //     var newArr=[];
        //     for(var i=0;i<this.length;i++){
        //         if(i%2==0){
        //             newArr.push(this[i]);
        //         }
        //     }   
        //     return newArr;
        // };  
        // var arrs=["alice","cici","lili","lucy","huahua","xinxin"];
        // var res=arrs.selectOdd();
        // console.log(res);
        //为数组添加一个共享方法，交换数组中两个元素的位置，并返回这个数组，两个参数
        Array.prototype.changeLoc=function(index1,index2){
            var temp=this[index1];
            this[index1]=this[index2];
            this[index2]=temp;
            return this;
        };
        var arrs=["alice","cici","lili","lucy","huahua","xinxin"];
        var res=arrs.changeLoc(1,4);
        console.log(res);

        function Person(name){
            this.name=name;
        }
        function Student(name){
            this.name=name;
        }
        Student.prototype.sex="男";
        var p=new Person("cici");
        console.log(p.sex);
        var stu=new Student("aa");
        console.log(stu.sex);
    </script>
</body>
</html>